﻿using Hangfire;
using Hicap.QRCodeWarehouse.Core.Managers;
using Microsoft.AspNetCore.Builder;

namespace Hicap.QRCodeWarehouse.Core.Extensions
{
    public static class GlobalJobsExtension
    {
        public static IApplicationBuilder UseGlobalJobs(this IApplicationBuilder app)
        {
            CreateGlobalJobs(app);
            return app;
        }

        private static void CreateGlobalJobs(IApplicationBuilder app)
        {
            if (JobStorage.Current.GetConnection()
            .GetAllEntriesFromHash($"recurring-job:{SysConsts.MonitorRecurringJobName}") == null)
                RecurringJob.AddOrUpdate<IMonitorManager>(SysConsts.MonitorRecurringJobName, x => x.GetMonitorInfos(1), Cron.HourInterval(SysConsts.MonitorIntervalHours));
        }
    }
}